//
//  KBMoreListViewController.m
//  喜马拉雅改良版框架
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//
// 点击"小编推荐"更多页面
#import "KBMoreListViewController.h"

@interface KBMoreListViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong)NSMutableArray *dataArray;
@property (nonatomic, strong)UITableView *myTableView;
@property (nonatomic, assign)NSInteger top; // 用来刷新

@end

@implementation KBMoreListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = _myTitle;
    _dataArray = [NSMutableArray array];
    _myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    // 代理
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    
    // 注册
    [_myTableView registerClass:[KBMoreListTableCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_myTableView];
    [self getData];
}

- (void)getData
{
    [AFNetworkTool getUrl:_moreUrl body:self result:HXJSON headerFile:nil success:^(id result)
    {
       
        NSMutableArray *list = [result objectForKey:@"list"];
        for (NSDictionary *dic in list)
        {
            KBMoreListModel *model = [[KBMoreListModel alloc]initWithDictionary:dic];
            [_dataArray addObject:model];
        }

        [_myTableView reloadData];
        
    } failure:^(NSError *error)
    {
        
        NSLog(@"数据请求失败");
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    KBMoreListTableCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    KBMoreListModel *model = [_dataArray objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.model = model;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 86;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    KBMoreListModel *model = [_dataArray objectAtIndex:indexPath.row];
    KBAlbumsDetailViewController *AlbumsVC = [[KBAlbumsDetailViewController alloc]init];
    AlbumsVC.albumId = [NSString stringWithFormat:@"%@", model.albumId];
    [self.navigationController pushViewController:AlbumsVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
